﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Me.Prettyprint.Hector.Api.Ddl;

namespace Me.Prettyprint.Cassandra.Serializers
{
    /// <summary>
    /// BytesArraySerializer will convert the bytes from little endian
    /// encoding back and forth.
    /// </summary>
    public class BytesArraySerializer : AbstractSerializer<byte[]>
    {
        public static BytesArraySerializer Instance = new BytesArraySerializer();

        public BytesArraySerializer()
        {
        }
        public override ComparatorType GetComparatorType()
        {
            return ComparatorType.BYTESTYPE;
        }
        override public ComparatorType ComparatorType
        {
            get
            {
                return ComparatorType.BYTESTYPE;
            }
        }
        public override byte[] ToBytes(byte[] bytes)
        {
            return ConvertToBigEndianBytes(bytes);
        }
        public override Utils.ByteBuffer ToByteBuffer(byte[] obj)
        {
            return new Utils.ByteBuffer(ToBytes(obj));
        }
        public override byte[] FromBytes(byte[] bytes)
        {
            return ConvertFromBigEndianBytes(bytes);
        }
        public override byte[] FromByteBuffer(Utils.ByteBuffer buff)
        {
            return FromBytes(buff.GetBuffer());
        }
    }
}
